package com.geeaks.learn.rename;

import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

public class RenameUtils {
	
	public static void main(String[] args) {
		renameA();
//		renameB();
	}
	
	static void renameA() {
		String path = "/Users/geeaks/Movies/";
		File directory = FileUtils.getFile(path);
		for(File file : directory.listFiles()) {
			if(file.getName().startsWith("黄金") && file.isFile()) {
				String newName = StringUtils.substring(file.getName(), 0,5)+StringUtils.substring(file.getName(), StringUtils.lastIndexOf(file.getName(), "."),file.getName().length());
				System.out.println(newName);
				File dest = new File(path+"/黄金瞳/"+newName);
				file.renameTo(dest);
			}
		}
	}
	
	static void renameB() {
		String path = "/Users/geeaks/Downloads/人人影视";
		File directory = FileUtils.getFile(path);
		for(File dir : directory.listFiles()) {
			//无耻家庭.Shameless.US.S09E09
			if(dir.isDirectory() && StringUtils.contains(dir.getName(), "无耻家庭 第9季")) {
				for(File file : dir.listFiles()) {
					String newName = removeArr(file.getName(),
						".Shameless.US.S09E",
						".中英字幕.WEBrip.720P-人人影视"
					);
					System.out.println(newName);
					File dest = new File(path+File.separator+dir.getName()+File.separator+newName);
					file.renameTo(dest);
				}
			}
		}
	}
	
	static String removeArr(String source,String... strArr) {
		for(String str : strArr) {
			source = StringUtils.remove(source, str);
		}
		return source;
	}
}
